package com.bjc.base.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

import com.bjc.base.bean.request.UserReqVO;

import me.chanjar.weixin.mp.bean.result.WxMpUser;

/**
 * 微信用户和本地用户的转换
 * @author admin
 *
 */
public class UserReqVOAndWxMpUser {

	/**
	 * 微信用户转换成本地用户
	 * @param reqVO
	 * @param user
	 */
	public static void setUserReqVOByWxMpUser(UserReqVO reqVO, WxMpUser user) {
		reqVO.setOpenid(user.getOpenId());
		reqVO.setSubscribe(user.getSubscribe() == true ? 1 : 0);
		reqVO.setNickname(user.getNickname());
		reqVO.setSex(user.getSex());
		reqVO.setLanguage(user.getLanguage());
		reqVO.setCity(user.getCity());
		reqVO.setProvince(user.getProvince());
		reqVO.setCountry(user.getCountry());
		reqVO.setHeadimgurl(user.getHeadImgUrl());
		reqVO.setSubscribeTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(user.getSubscribeTime() * 1000L),
				ZoneId.of("Asia/Shanghai")));
	}

}
